from pymem import *


# def FindBaseAddr(addr):
#   for addr in range(pm.base_address, )
#
#
# pm = Pymem('Tutorial-x86_64.exe')
# pid = pm.process_id
# print('pid=', pid)
# print(pm.read_int(0x05E81898))

# 打开目标进程
pm = pymem.Pymem('Tutorial-x86_64.exe')  # 替换为目标进程名

# 获取目标模块信息
module = pymem.process.module_from_name(pm.process_handle, 'Tutorial-x86_64.exe')  # 替换为目标模块名

# 获取模块的基址和范围
base_address = module.lpBaseOfDll
module_size = module.SizeOfImage
end_address = base_address + module_size
print('模块基址=', base_address)
print('模块大小=', module_size)
print('模块终址=', end_address)
# 假设我们感兴趣的地址
address_of_interest = 0x100325B00  # 替换为你感兴趣的地址

# 检查地址是否在模块范围内
if base_address <= address_of_interest <= end_address:
  print(f"地址 0x{address_of_interest:X} 在模块范围内")

  try:
    # 尝试读取该地址的数据（4字节）
    value = pm.read_int(address_of_interest)
    print(f"地址 0x{address_of_interest:X} 的值为: {value}")
    print("地址有效，可能是一个基址")
  except pymem.exception.MemoryReadError:
    print("无法读取地址，地址无效")
else:
  print(f"地址 0x{address_of_interest:X} 不在模块范围内")
